package fr.ants.model.stats;

import java.util.LinkedList;
import java.util.Queue;

/**
 * Statistics gathered during a cycle.
 *
 * @author Vianney DUPOY DE GUITARD
 */
public class CycleStatistic {

	/** Current nest. */
	private NestStatistics currentNest;

	/** Amount of resources available. */
	private float resourcesAvailable = 0;

	/** Statistics related to a nest during a cycle. */
	private Queue<NestStatistics> nestStats = new LinkedList<>();

	/**
	 * @return the nestStats
	 */
	public Queue<NestStatistics> getNestStats() {
		return nestStats;
	}

	/**
	 * Adds a new nest statistics object.
	 * @return the new nest.
	 */
	public NestStatistics newNest() {
		currentNest = new NestStatistics();
		nestStats.add(currentNest);
		return currentNest;
	}

	/** @return the total of explore steps during the cycle. */
	public int getExploreSteps() {
		int exploreSteps = 0;
		for (NestStatistics nest : nestStats) {
			exploreSteps += nest.getAntExploreSteps();
		}
		return exploreSteps;
	}

	/** @return the total of 'follow' steps during the cycle. */
	public int getFollowSteps() {
		int followSteps = 0;
		for (NestStatistics nest : nestStats) {
			followSteps += nest.getAntFollowSteps();
		}
		return followSteps;
	}

	/** @return the total of 'coming back to nest' steps during the cycle. */
	public int getToNestSteps() {
		int toNestSteps = 0;
		for (NestStatistics nest : nestStats) {
			toNestSteps += nest.getAntToNestSteps();
		}
		return toNestSteps;
	}

	/** @return the total of crops during the cycle. */
	public int getCrops() {
		int crops = 0;
		for (NestStatistics nest : nestStats) {
			crops += nest.getAntCrops();
		}
		return crops;
	}

	/** @return the total of deposits during the cycle. */
	public int getDeposits() {
		int deposits = 0;
		for (NestStatistics nest : nestStats) {
			deposits += nest.getAntDeposits();
		}
		return deposits;
	}

	/** @return the amount of resources owned by the nests. */
	public float getNestResources() {
		float resources = 0;
		for (NestStatistics nest : nestStats) {
			resources += nest.getResourceCount();
		}
		return resources;
	}

	/** @return the amount of resources carried by ants. */
	public float getResourcesInTransit() {
		float resources = 0;
		for (NestStatistics nest : nestStats) {
			resources += nest.getResourcesInTransit();
		}
		return resources;
	}

	/**
	 * @return the resourcesAvailable
	 */
	public float getResourcesAvailable() {
		return resourcesAvailable;
	}

	/**
	 * @param resources : the amount of resources to add.
	 */
	public void addResourcesAvailable(float resources) {
		this.resourcesAvailable += resources;
	}
}
